import java.util.ArrayList;
import java.util.Random;


public class Deck {
    final int CARDNUMBER = 52;
    ArrayList<Card> cards;

    public Deck()
    {
        cards = new ArrayList<>(CARDNUMBER);
        generateDeck();

    }

    public void addCards(ArrayList<Card> CardsToAdd)
    {
        if(cards.size()+CardsToAdd.size()<= 52)
            cards.addAll(CardsToAdd);
    }

    private void generateDeck()
    {
        Colour[] colours = Colour.values();
        Rank[] ranks = Rank.values();


        for(Colour colour : colours)
        {
            for(Rank rank : ranks)
            {
                cards.add(new Card(rank,colour));
            }
        }

    }

    public int cardnumber()
    {
        return cards.size();
    }

    public Card typeCard()
    {
        Random rnd = new Random();
        return cards.remove(rnd.nextInt(cardnumber()));
    }

    public Hand typeHand()
    {
        ArrayList<Card> hand = new ArrayList<>(5);

        hand.add(typeCard());
        hand.add(typeCard());
        hand.add(typeCard());
        hand.add(typeCard());
        hand.add(typeCard());

        return new Hand(hand);
    }

    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        int num = 1;
        for(Card c : cards)
        {
            sb.append(c).append(" | ");
            if(num++ % 10 == 0)
                sb.append("\n");
        }
        return sb.toString();
    }

}
